package com.rober.algorithm;

/**
 * @For: 简单的工厂模式
 * @author roberluo
 *
 */
public class EasyFactory {
	public static void main(String[] args) {
		// 随意调用
		Car car = CarFactory.getCar("baoma");
		car.name();
	}
}

// 工厂类接口
interface Car{
	void name();
}

// 奔驰-生产线
class bench implements Car{
	@Override
	public void name() {
		System.out.println("I buy a bench");
	}
	
}

//宝马-生产线
class baoma implements Car{
	@Override
	public void name() {
		System.out.println("I buy a baoma");
	}
}

// 车工厂
class CarFactory{
	  static Car getCar(String car) {
		if(car == "bench") {
			return new bench();
		}
		if(car == "baoma") {
			return new baoma();
		}
		return null;
	
	}
}


